Automating Office forms from VBScript

Microsoft Outlook uses the Office form to display Microsoft Office documents posted to a folder or sent to a user. You cannot change the pages and controls displayed on the form, but you can add Microsoft Visual Basic Scripting Edition (VBScript) code to the form.

You can use the GetObject statement in VBScript to access an embedded Office document in an Outlook Office form.

The following sample VBScript code inserts "This is from VBScript!" into the embedded Microsoft Word document in a Microsoft Word Office form. Because the code is in the Open event procedure, the code runs automatically when the item opens. You can expand on this simple example to provide more useful results, such as inserting a formatted list of appointments.

Sub Item_Open()
   Set objWord = GetObject(, "Word.Application")
   ' Use Word methods to insert some sample text
   objWord.Selection.TypeText "This is from VBScript!"
End Sub